$(function () {
    $('#login').click(function () {
        $.ajax({
            url: '/user/login/check',
            type: 'post',
            async: false,
            data: {
                username: $("#login-username").val(),
                password: $("#login-password").val()
            },
            success: data => {
                if (data.code == 0) {
                    window.location.href = '/map'
                }
                else {
                    window.alert(data.info)
                }
            },
            error: data => {
                console.log(data)
            }
        })
    })

    $("#register").click(function () {
        $.ajax({
            url: '/user/register/check',
            type: 'post',
            async: false,
            data: {
                username: $("#signup-username").val(),
                password: $("#signup-password").val(),
                confirm_password: $("#signup-confirm-password").val(),
                agree_volunteer: $("#agree-volunteer").val(),
            },
            success: data => {
                if (data.code == 0) {
                    window.location.href = '/map'
                }
                else {
                    window.alert(data.info)
                }
            },
            error: data => {
                console.log(data)
            }
        })
    })
})